package com.jdk.demo.aio.重复读与重复写异常;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.Future;

public class 重复读 {

	public static void main(String[] args) throws Exception {
		// 如果一个线程，在上一次读操作没有完成之前(调用get方法)，启动了read操作，则会引发异常java.nio.channels.ReadPendingException
		AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open().bind(new InetSocketAddress("127.0.0.1", 8013));
		Future<AsynchronousSocketChannel> future = server.accept();
		AsynchronousSocketChannel socketChannel = future.get();
		ByteBuffer bytebuffer = ByteBuffer.allocate(20);
		Future<Integer> f1 = socketChannel.read(bytebuffer);
		Future<Integer> f2 = socketChannel.read(bytebuffer);
	}

}
